﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Architecture.CrossCutting.LoggingEntities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Architecture.CrossCutting.Tracing.Models;
//using Microsoft.Practices.Unity;
//using Repository.Pattern.DataContext;
//using Repository.Pattern.UnitOfWork;
//using Repository.Pattern.Repositories;
//using Repository.Pattern.Ef6;

namespace Architecture.CrossCutting.LoggingEntities.Tests
{
    [TestClass()]
    public class LoggingRepositoryTests
    {
        //private UnityContainer _container;

        [TestInitialize()]
        public void Initialize()
        {
            //_container = new UnityContainer();
            //_container.RegisterType<IDataContextAsync, LoggingServiceContext>()
            //    .RegisterType<IUnitOfWorkAsync, UnitOfWork>()
            //    .RegisterType<IRepositoryAsync<Log>, Repository<Log>>();

        }
        [TestMethod()]
        public void AddIISLogTest()
        {

            Guid newRequestId = Guid.NewGuid();

            using (var ctx = new LoggingServiceContext())
            {

                IISLog log = new IISLog()
                {
                    RequestId = newRequestId
                };


                ctx.IISLogs.Add(log);
                ctx.SaveChanges();
            }

            using (var ctx = new LoggingServiceContext())
            {
                var query = ctx.IISLogs.Where(l => l.RequestId.Equals(newRequestId));
                var log = query.FirstOrDefault();

                Assert.IsNotNull(log);                
            }

        }

        [TestMethod()]
        public void GetTest()
        {
            using (var ctx = new LoggingServiceContext())
            {
                var c = new LoggingRepository<Log>(ctx);
                var logs = c.Get(q => q.Where(l => l.CreationDate >= DateTime.Today));
                Assert.IsTrue(logs.Count() > 0);
            }

        }

        [TestMethod()]
        public void GetTest_WithExpression()
        {
            using (var ctx = new LoggingServiceContext())
            {
                var c = new LoggingRepository<Log>(ctx);
                var logs = c.Get(l => l.CreationDate >= DateTime.Today);
                Assert.IsTrue(logs.Count() > 0);
            }
        }

        [TestMethod()]
        public void GetQueryTest_WithExpression()
        {
            using (var ctx = new LoggingServiceContext())
            {
                var c = new LoggingRepository<Log>(ctx);
                var logs = c.GetQuery(l => l.CreationDate >= DateTime.Today);
                Assert.IsTrue(logs.Count() > 0);
            }
        }

        [TestMethod()]
        public void GetQueryTest()
        {
            using (var ctx = new LoggingServiceContext())
            {
                var c = new LoggingRepository<Log>(ctx);
                var logs = c.GetQuery(q => q.Where(l => l.CreationDate >= DateTime.Today));
                Assert.IsTrue(logs.Count() > 0);
            }
        }
    }
}